package frog.lazy.framework.core.dto;

import lombok.Data;
import lombok.experimental.SuperBuilder;

import java.io.Serializable;

@Data
@SuperBuilder
public class ResultDto implements Serializable {
    private static final long serialVersionUID = 7418517202519442699L;

    private static final Integer SUCCESS = 200;

    private static final Integer FAIL = 400;

    private static final Integer NO_LOGIN = 403;

    private static final Integer RE_LOGIN = 401;

    private static final Integer ERROR = 500;

    private Integer code;

    private Object data;

    private String msg;

    public static ResultDto success(Object obj, String msg) {
        return ResultDto.builder()
                .code(SUCCESS)
                .msg(msg)
                .data(obj)
                .build();
    }

    public static ResultDto success(Object obj) {
        return success(obj, "操作成功");
    }

    public static ResultDto success(String msg) {
        return success(null, msg);
    }

    public static ResultDto success() {
        return success((Object)null);
    }

    public static ResultDto fail(Object obj, String msg) {
        return ResultDto.builder()
                .code(FAIL)
                .msg(msg)
                .data(obj)
                .build();
    }

    public static ResultDto fail(Object obj) {
        return fail(obj, "操作失败");
    }

    public static ResultDto fail(String msg) {
        return fail(null, msg);
    }

    public static ResultDto fail() {
        return fail((Object)null);
    }

    public static ResultDto error(Object obj, String msg) {
        return ResultDto.builder()
                .code(ERROR)
                .msg(msg)
                .data(obj)
                .build();
    }

    public static ResultDto error(Object obj) {
        return error(obj, "操作失败");
    }

    public static ResultDto error(String msg) {
        return error(null, msg);
    }

    public static ResultDto error() {
        return error((Object) null);
    }

    public static ResultDto noLogin(String msg) {
        return ResultDto.builder()
                .code(NO_LOGIN)
                .msg(msg)
                .build();
    }

    public static ResultDto noLogin() {
        return noLogin("未登录");
    }

    public static ResultDto reLogin(Object obj) {
        return ResultDto.builder()
                .data(obj)
                .code(RE_LOGIN)
                .msg("使用新凭证重试")
                .build();
    }

}
